﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Elkitools.EditorParts.ListSelector.Tools;

namespace Elkitools.EditorParts.ListSelector
{
    [Serializable]
    internal class CalendarListData
    {
        //-------------------------------------------------------------------------
        #region Properties
        //-------------------------------------------------------------------------

        /// <summary>
        /// Name of the SPList
        /// </summary>
        internal string Title { get; set; }

        /// <summary>
        /// Server-relative Url of the SPList
        /// </summary>
        internal string ServerRelativeUrl { get; set; }

        /// <summary>
        /// Url of the display form (to be used when opening the popups if necessary)
        /// </summary>
        internal string DisplayFormUrl { get; set;}

        //-------------------------------------------------------------------------
        #endregion Properties
        //-------------------------------------------------------------------------

        //-------------------------------------------------------------------------
        #region Constructor & initializations
        //-------------------------------------------------------------------------

        /// <summary>
        /// Default Constructor
        /// </summary>
        internal CalendarListData()
        {
        }

        /// <summary>
        /// Constructor that takes the refence SPList as parameter
        /// </summary>
        /// <param name="pobjWeb"></param>
        internal CalendarListData(SPList pobjList) : this()
        {
            InitializeData(pobjList);
        }

        /// <summary>
        /// Initilize internal data
        /// </summary>
        /// <param name="pobjWeb"></param>
        private void InitializeData(SPList pobjList)
        {
            try
            {
                this.Title = pobjList.Title;
                this.ServerRelativeUrl = pobjList.RootFolder.ServerRelativeUrl;
                this.DisplayFormUrl = pobjList.DefaultDisplayFormUrl;
            }
            catch (Exception excBasicData)
            {
                UlsLogger.Error("An error occurred while initializing basic data in CalendarListData : " + excBasicData.Message);
            }
        }

        //-------------------------------------------------------------------------
        #endregion Constructor & initializations
        //-------------------------------------------------------------------------

    }
}
